module namespace managecookie = "http://www.xmlproject.com/smi/lib/controller/managecookie";

import module namespace cookie="http://www.28msec.com/modules/http/cookie";
import module namespace html = "http://www.zorba-xquery.com/modules/tidy";

declare sequential function managecookie:createCookie($values)
{
     cookie:set-cookie(
            <cookie:cookie
                name="searched" >
                <cookievalue>
                    {$values}
                </cookievalue>
            </cookie:cookie>
          );
          "cookie created";
};

declare sequential function managecookie:setCookie($query as xs:string)
{
(: Create the guest cookie :)
        let $c := cookie:get-cookies("searched")
        
        let $old := 
        for $t in $c//cookievalue/movies/search
        return <search>{$t/text()}</search> 
            
        let $all := <movies>{$old}<search>{$query}</search></movies>
        (:let $queryvalue := <search>{$query}</search>:)
        
        let $empty := managecookie:createCookie($all)
        return $empty
};

declare sequential function managecookie:getCookie()
{
    let $c := cookie:get-cookies("searched")
    let $res := if( $c = "" )
    then
        "vacio"
    else
         $c
    return $res
};


